import cvlib as cv
import cv2
from matplotlib import pyplot as plt


# 可视化函数
def show_img_with_matplotlib(color_img, title, pos):
    img_RGB = color_img[:, :, ::-1]
    ax = plt.subplot(1, 1, pos)
    plt.imshow(img_RGB)
    plt.title(title, fontsize=8)
    plt.axis('off')


# 第四种方法同样需要且仅需要一行代码
# image = cv2.imread('安全分析技术汇总.png')
# faces, confidences = cv.detect_face(image)


# 绘制边界框
def show_detection(image, faces):
    # for (startX, startY, endX, endY) in faces:
    #     cv2.rectangle(image, (startX, startY), (endX, endY), (255, 0, 0), 3)
    for (startX, startY, endX, endY) in faces:
        cv2.rectangle(image, (startX, startY), (endX, endY), (255, 0, 0), 3)
    return image


# # 可视化
# img_result = show_detection(image.copy(), faces)
# show_img_with_matplotlib(img_result, "cvlib face detector: " + str(len(faces)), 1)
# plt.show()
